package com.kemai.designmode.ui
import android.os.Bundle
import com.kemai.common.adapter.ItemClickListener
import com.kemai.common.ui.BaseActivity
import com.kemai.common.utils.AppUtils
import com.kemai.designmode.R
import com.kemai.designmode.factory.builder.Builder
import com.kemai.designmode.factory.builder.HolidayMealBuilder
import com.kemai.designmode.factory.builder.MemberMealBuilder
//建造者工厂模式调用(将一个组合设置放入到一个工厂里)
class BuildModeActivity : BaseActivity(), ItemClickListener {
    private val studyContent = arrayOf("会员套餐","节日套餐")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_common_content)
        findViewById()
        setTiTle("建造者工厂模式")
        setAdapterContent(studyContent,BuildModeActivity@this,BuildModeActivity@this)
    }

    override fun itemClick(position: Int) {
       var builder: Builder
      when(position){

          0->{//会员套餐
              builder = MemberMealBuilder()
              builder.buildApple(80.0)
              builder.buildBanana(85.0)
              builder.buildOrange(60.0)
              val fruitMeal = builder.getFruitMeal()
              AppUtils.getInstance()?.showToast("会员套餐价格为:${fruitMeal.totalCount}")

          }
          1->{//节日套餐
              builder = HolidayMealBuilder()
              builder.buildApple(80.0)
              builder.buildBanana(85.0)
              builder.buildOrange(60.0)
              val fruitMeal = builder.getFruitMeal()
              AppUtils.getInstance()?.showToast("假日套餐价格为:${fruitMeal.totalCount}")
          }
      }
    }

}